/*
 * exame_2009_10_julho_Q2.c
 *
 *  Created on: Jun 19, 2012
 *      Author: ubuntu
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int mystrcspn(char * s1, char * s2) {

	int i = 0;
	int conta = 0;
	for (i = 0; s1[i] != '\0'; i++) {
		int j = 0;
		int flagFoundCharacter = 0;
		for (j = 0; s2[j] != '\0'; j++) {
			if (s1[i] == s2[j]) {
				flagFoundCharacter = 1;
				break;
			}
		}
		if (flagFoundCharacter == 0) {
			conta++;
		} else {
			break;
		}
	}
	return conta;

}

int main(int argc, char **argv) {

	if (argc < 3) {
		fprintf(stderr, "Usage %s <s1> <s2>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	printf("strcspn: %d\n", strcspn(argv[1], argv[2]));
	printf("mystrcspn: %d\n", mystrcspn(argv[1], argv[2]));

	return 0;

}

